class_name StateMachine
extends Node

const CURRENT_STATE := -1

var current_state:int = -1:
	set(v):
		owner.transition_state(current_state,v)
		current_state = v
		state_time = 0.0

var state_time:float = 0   #用于记录当前状态的持续时间

func _ready() -> void:
	await owner.ready #等待父节点ready信号
	current_state = 0
	
func _physics_process(delta: float) -> void:
	while true:
		var next := owner.get_next_state(current_state) as int
		if CURRENT_STATE == next:
			break
		current_state = next
		
	owner.tick_physics(current_state,delta)
	state_time += delta
